home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 May: Tool Chest / Dev.CD May 97 TC.toast / Tool Chest / Toolbox / System 7.0 Menu Def Info / MenuHints.a
Encoding:
Text File  |  1991-05-02  |  6.5 KB  |  195 lines  |  [TEXT/MPS ]

  1. These are notes on how to behave like the 7.0 MDEF.
  2. Note that this applies only to color machines.
  3.  
  4. There are 3 things you will want to do:
  5. 1) Draw disabled items in “true gray”
  6. 2) Draw lines (dashes) in “true gray”
  7. 3) Support Balloon Help properly.
  8.  
  9. *************************************************************************************
  10. DEFINITION:    True Gray - the "average" of the foreground and background color.
  11.                 Black fgnd and White bkgnd yields a nice gray.
  12.                 Red fgnd and White bkgnd yields a nice pink.
  13.  
  14.                 Q: How do I get this average correctly?
  15.                 A: There is a new trap _GetGray which does this for you!
  16.  
  17.                 In the MPW interface file "Palettes.[acp]" is the prototype:
  18.     FUNCTION GetGray(device: GDHandle;bkgnd: RGBColor;VAR fgnd: RGBColor): BOOLEAN;
  19.  
  20.                 where:    (note that menus never span monitors)
  21.                             device - is the device on which you are drawing
  22.                             bkgnd  - is the RGB color of the background
  23.                             fgnd   - is the RGB color of your ENABLED text
  24.  
  25.                 returns:    TRUE if there was an available color between the ones given
  26.                                   and fgnd is replace with that "gray" RGB value.
  27.  
  28.                             FALSE if the was no RGB color between the two given and
  29.                                   you should bitclear the text the old way.
  30.  
  31. *************************************************************************************
  32. #1 - Drawing disabled items in gray
  33.  
  34.     Call GetGray with the current foreground and background colors for the
  35.     current item derived from the 'mctb' if any.  If it returns false, use
  36.     the B&W algorithm.  Otherwise, set the foreground color and draw the item.
  37.     Remember to use the correct entries in the 'mctb' for each part of the item.
  38.  
  39. *************************************************************************************
  40. #2 - Drawing gray lines for the dash item
  41.  
  42. ;---------------------------------------
  43. ;    Utility -- DrawDash
  44. ;---------------------------------------
  45. ; handle the case of a dash item by drawing a line
  46. DrawDash
  47.  
  48.             TST.B    onColorMachine(A6)    ; Are we on a color machine?
  49.             BEQ.S    @ditherGrayLine        ; If not, draw dithered line
  50.  
  51. ;    FUNCTION GetGray(device: GDHandle; backGround: RGBColor; VAR foreGround: RGBColor): BOOLEAN;
  52.  
  53.             sub        #12,sp                ; put (back,fore) colors on stack
  54.             pea        (sp)
  55.             _GetBackColor
  56.             pea        6(sp)
  57.             _GetForeColor
  58.             subq    #6,sp                ; Make room for result & gdhandle
  59.             move.l    MMenuRect(a6),-(sp)    ; Global menu rect
  60.             _GetMaxDevice                ; leave main device on stack
  61.             lea        6(sp),a0            ; Get address of back color
  62.             move.l    a0,-(sp)            ; Push back
  63.             pea        6(a0)                ; Push fore
  64.             _GetGray                    ; Do we have a gray?
  65.             move.b    (sp)+,d0
  66.             bne.s    @rgbGrayLine        ; NE (TRUE) means we have the gray
  67.             add        #12,sp
  68.             bra.s    @ditherGrayLine
  69. @rgbGrayLine
  70.             addq    #6,sp                ; Get rid of back color
  71.             pea        (sp)
  72.             _RGBForeColor
  73.             addq    #6,sp                ; Get rid of fore color
  74.             bra        @b
  75.  
  76. @ditherGrayLine
  77.             MOVE.L    (A5),A0                ; get QuickDraw globals
  78.             PEA        Gray(A0)            ; set pattern to gray
  79.             _PenPat
  80. @b
  81.             MOVE.W    D3,-(SP)            ; save y position
  82.             MOVE.W    D5,-(SP)            ; push x position
  83.             MOVE.W    MFHeight(A6),D0    ; center the dash
  84.             LSR.W    #1,D0                ; by backing up to top of cell
  85.             SUB.W    MAscent(A6),D0        ; and going halfway down
  86.             ADD.W    D0,D3                ; add to current position
  87.             MOVE.W    D3,-(SP)            ; push new y position
  88.             _MoveTo
  89.  
  90.             MOVE.W    D6,-(SP)            ; push    right edge
  91.             MOVE    D3,-(SP)            ; push    y
  92.             _LineTo                        ; draw    the line
  93.             MOVE.W    (SP)+,D3            ; restore baseline
  94.  
  95.             _PenNormal                    ; This won’t create a new pixpat
  96. @oldMac2
  97.             BRA        DoneDrawItem        ; dive    back into mainstream
  98.  
  99. *************************************************************************************
  100. #3 - Balloon Help support
  101.  
  102. ;; Inside the CHOOSE message *after* inverting the chosen item...
  103.  
  104.             SUBQ    #2,SP                    ; room for Boolean
  105.             _HMGetBalloons                    ; what is the state of What Is? mode? (This is a FAST call)
  106.             TST.B    (SP)+
  107.             BEQ.S    @FlashInProgress
  108.  
  109.             SUBQ    #2,SP                    ; check status of button
  110.             _StillDown
  111.             TST.B    (SP)+                    ; if true then button is still down
  112.             BEQ.S    @FlashInProgress        ;    else the item is flashing so don’t flash the balloon
  113.  
  114.             BSR.S    ShowMenuBalloon            ; show the balloon for the chosen item
  115.  
  116. @FlashInProgress
  117.  
  118. ;; Other stuff to finish off CHOOSE message
  119.             rts                            ; return to dispatcher
  120.  
  121. ;---------------------------------------
  122. ;    Utility -- RemoveAnyBalloon
  123. ;---------------------------------------
  124. ;
  125. ; Insure no balloon is currently displayed.
  126. ; Remove balloons should be called before scrolling or when changing from one item to another.
  127. ; and when the mouse is over a dash.
  128. ;
  129. ; Note: The standard MBDF removes any balloon before saving bits for or
  130. ; restoring bits from a menu (or hierarchical menu) since menu balloons save bits too.
  131. ;
  132. RemoveAnyBalloon
  133.             subq    #2,sp                    ; room for Boolean
  134.             _HMGetBalloons                    ; Show Balloons?
  135.             tst.b    (sp)                    ; EQ means off (leave result on stack for now)
  136.             beq.s    @helpIsOff
  137.             _HMRemoveBalloon                ; Remove any balloons before scrolling
  138. @helpIsOff
  139.             addq    #2,sp                    ; room for Boolean
  140.             rts
  141.  
  142.  
  143. ;---------------------------------------
  144. ;    Utility -- ShowMenuBalloon
  145. ;---------------------------------------
  146. ;
  147. ; Show the balloon for this item.
  148. ;
  149. ShowMenuBalloon
  150.             MOVE.L    D4,-(SP)                ; Save only the needed registers!
  151.  
  152.             MOVE.L    (A3),A0                    ; get menuPtr
  153.             MOVE    D4,D0                    ; get item number
  154.             BSR        GETITEMRECORD            ; look it up
  155.             BSR        IsDash                    ; Is it a dash? (other attrs?)
  156.             BNE.S    @needBalloon            ; no, just return the item num
  157.             MOVEQ    #-1,D4                    ; else make item num -1 for dash
  158. @needBalloon
  159.  
  160. ;    FUNCTION  HMShowMenuBalloon(itemNum,itemMenuID: INTEGER;
  161. ;                                itemFlags,itemReserved: LONGINT;
  162. ;                                tip: Point; alternateRect: RectPtr; tipProc: Ptr;
  163. ;                                theProc,variant: INTEGER): OSErr;
  164.  
  165.             SUBQ    #2,SP                    ; room for result
  166.             MOVE.W    D4,-(SP)                ; item number
  167.  
  168.             MOVE.L    (A3), A0                ; get menu ptr
  169.             MOVE.W    menuID(A0),-(SP)        ; push menuID
  170.             MOVE.L    MENUENABLE(A0),D0        ; get menu flags in D0
  171.             MOVE.L    D0,-(SP)                ; push menu flags
  172.  
  173.             MOVE.L    #0,-(SP)                ; push help string handle in itemReserved
  174.  
  175.             MOVE.L    MBSaveLoc,A0            ; get MBSave handle
  176.             MOVE.L    (A0),A0                    ; deref
  177.             MOVE.W    mbItemRect+bottom(A0),D4
  178.             SUB.W    mbItemRect+top(A0),D4
  179.             LSR.W    #1,D4                    ; find half way down from top of menu
  180.             MOVE.L  mbItemRect+botRight(A0),D0    ; use the right side of the menu rect
  181.             SUBQ.W    #BalloonTipOverlap,D0    ;    tweak the horizontal part
  182.             SWAP    D0
  183.             SUB.W    D4,D0                   ; put the tip in the middle of the right vert
  184.             SWAP    D0
  185.             MOVE.L    D0,-(SP)                ; push the tip
  186.  
  187.             PEA        mbItemRect(A0)            ; push the alternaterect
  188.             CLR.L    -(SP)                    ; NIL tipProc
  189.             CLR.L    -(SP)                    ; theProc & variant = 0
  190.             _HMShowMenuBalloon
  191.             ADDQ    #2,SP                    ; toss result
  192.  
  193.             MOVE.L    (SP)+,D4                ; Restore saved registers.
  194.             RTS
  195.